import { fakeChartData } from '@/services/api';

export default {
  namespace: 'chart',

  state: {
    visitData: [],
    visitData2: [],
    searchData: [],
    offlineData: [],
    offlineChartData: [],
    radarData: [],
    loading: false,

    studentData: [],
    collegeRankingAttendance: [],
    collegeRankingEvaluation: [],
    attendanceRate: [],
    ascensionRate: [],

    incomeData: [],
    customOutcomeData: [],
    capitalOutcomeData: [],
    tags: [],
  },

  effects: {
    *fetch(_, { call, put }) {
      const response = yield call(fakeChartData);
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *fetchSalesData(_, { call, put }) {
      const response = yield call(fakeChartData);
      yield put({
        type: 'save',
        payload: {
          salesData: response.salesData,
        },
      });
    },
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
    clear() {
      return {
        visitData: [],
        visitData2: [],
        salesData: [],
        searchData: [],
        offlineData: [],
        offlineChartData: [],
        radarData: [],

        studentData: [],
        collegeRankingAttendance: [],
        collegeRankingEvaluation: [],
        attendanceRate: [],
        ascensionRate: [],

        incomeData: [],
        customOutcomeData: [],
        capitalOutcomeData: [],
        tags: [],
      };
    },
  },
};
